package com.stylefeng.guns.modular.goods.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.goods.model.ShopInfo;
import com.stylefeng.guns.modular.goods.service.IShopInfoService;

/**
 * 店铺信息 控制器
 *
 * @author fengshuonan
 * @Date 2018-09-05 16:10:38
 */
@Controller
@RequestMapping("/shopInfo")
public class ShopInfoController extends BaseController {

    private String PREFIX = "/goods/shopInfo/";

    @Autowired
    private IShopInfoService shopInfoService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "shopInfo.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/shopInfo_add")
    public String shopInfoAdd() {
        return PREFIX + "shopInfo_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/shopInfo_update/{shopInfoId}")
    public String shopInfoUpdate(@PathVariable Long shopInfoId, Model model) {
        ShopInfo shopInfo = shopInfoService.selectById(shopInfoId);
        model.addAttribute("item",shopInfo);
        LogObjectHolder.me().set(shopInfo);
        return PREFIX + "shopInfo_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return shopInfoService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ShopInfo shopInfo) {
        shopInfoService.insert(shopInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long shopInfoId) {
        shopInfoService.deleteById(shopInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ShopInfo shopInfo) {
        shopInfoService.updateById(shopInfo);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{shopInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("shopInfoId") Long shopInfoId) {
        return shopInfoService.selectById(shopInfoId);
    }
}
